package leetcode_2501_2600;

import java.awt.peer.CanvasPeer;
import java.util.Arrays;

public class LeeCode_2587 {
    public static void main(String[] args) {
        System.out.println(maxScore(new int[]{2, -1, 0, 1, -3, 3, -3}));
    }
    private static int maxScore(int[] nums) {
        int n = nums.length;
        Integer[] copy = new Integer[n];
        for (int i = 0; i < copy.length; i++) {
            copy[i] = nums[i];
        }
        Arrays.sort(copy, (o1, o2) -> o2- o1);
        long[] sums = new long[n + 1];
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            sums[i] = sums[i - 1] + copy[i - 1];
            if (sums[i] > 0){
                ans++;
            }
        }
        return ans;
    }
}
